<?php

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );
global $mainframe;

require_once $mainframe->getPath('class','com_docman'); 
require_once $mainframe->getPath('front_html','com_logs'); 

$_DOCMAN = new dmMainFrame(_DM_TYPE_ADMIN);

$task      = mosGetParam($_REQUEST,'task');
$gid       = mosGetParam($_REQUEST,'gid');
$resource  = mosGetParam($_REQUEST, 'resource');
$question1 = mosGetParam($_REQUEST, 'question1','');
$question2 = mosGetParam($_REQUEST, 'question2','');
$question3 = mosGetParam($_REQUEST, 'question3','');

$params_path = $mosConfig_absolute_path . '/administrator/components/com_docman/docman.params.xml';
include_once($_DOCMAN->getPath('classes', 'params'));

$query = 'SELECT attribs FROM #__docman WHERE id = '.$gid;
$database->setQuery($query);
$database->loadObject($document);


if(file_exists($params_path)) {
    $params =& new dmParameters( $document->attribs, $params_path , 'params' );
}

$params->render();
$object = $params->toObject();
$object->resource = $resource;

if(!isset($_SESSION))  session_start();
if(@$_SESSION['docman'.$gid] == 1){
    $url = "index2.php?option=com_docman&gid={$gid}&task=doc_download";
    echo "<script>
			setTimeout(initDownload, 100);
			setTimeout(goToHomePage, 2000);	
            function initDownload(){
                document.location.href='$url';
            }
            function goToHomePage(){
                document.location.href='$mosConfig_live_site';
            }
          </script>\n";
}else{
    if (($object->question1 && $question1 == '') ||
    ($object->question2 && $question2 == '') || 
    ($object->question3 && $question3 == '') ){
    logs_html::showQuestions($object);
    }else{
    if(!isset($_SESSION))  session_start();
    $_SESSION['docman'.$gid] = 1;
    $_SESSION['docmanquestion1'] = $question1;
    $_SESSION['docmanquestion2'] = $question2;
    $_SESSION['docmanquestion3'] = $question3;
        $resource = mosGetParam($_REQUEST,'resource','');
        mosRedirect("index2.php?resource=".$resource);
    }
}
?>